package _5thread;

/**
 * @description:
 * @author: wang zhen
 * @create: 2022-06-14 10:32
 */
public class LockSupportTest3 {


    public static void main(String[] args) {


        Thread threadA=new Thread("A线程"){
            @Override
            public void run() {

                while (true){

                    if(this.isInterrupted()){
                        System.out.println(Thread.currentThread().getName()+"收到停止通知，停止运行");
                        break;
                    }


                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                        break;

                    }

                    System.out.println(Thread.currentThread().getName()+"运行中");
                }

            }
        };

        threadA.start();


        new Thread("B线程"){
            @Override
            public void run() {

                try {Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}

                threadA.interrupt();
                System.out.println(Thread.currentThread().getName()+"发起停止通知");

            }
        }.start();

    }
}
